package com.founder.chd_daily_query.controller;

import com.founder.chd_daily_query.service.AlarmService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.lang.reflect.InvocationTargetException;

@RestController
@RequestMapping("/alarm")
public class AlarmController {
    @Autowired
    AlarmService alarmService;


    @GetMapping("/getAll/{model}/{page}/{num}")
    public Object getAll(@PathVariable("model") String model,
                         @PathVariable("page") Integer page,
                         @PathVariable("num") Integer num) throws ClassNotFoundException {
       return alarmService.queryForAllByPage(model,page,num);
    }

    @GetMapping(value = {"/getAlarmed/{model}/{page}/{num}","/getAlarmed/{model}/{page}/{num}/{startTime}/{endTime}"})
    public Object getAlarmed(@PathVariable("model") String model,
                         @PathVariable("page") Integer page,
                         @PathVariable("num") Integer num,
                         @PathVariable(value = "startTime",required = false) String startTime,
                         @PathVariable(value = "endTime",required = false) String endTime
                             ) throws ClassNotFoundException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
        return alarmService.queryForAlarmedByPage(model,page,num,startTime,endTime);
    }


    @GetMapping({"/relation/{model}/{field}/{key}"})
    public Object commonQuery(@PathVariable("model") String model, @PathVariable("field") String field, @PathVariable("key") String key) throws IllegalAccessException, InstantiationException, ClassNotFoundException, NoSuchMethodException, InvocationTargetException {
        return this.alarmService.RelationQuery(model, field, key);
    }



}
